package com.cxl.model;

public class Instruction {

	public int cmd;
	public int x1;
	public int y1;
	public int x2;
	public int y2;
	public int clickX;
	public int clickY;
	public byte[] byteBuf;
	

	public Instruction(int cmd, int x1, int y1, int x2, int y2, int clickX,
			int clickY) {
		super();
		this.cmd = cmd;
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		this.clickX = clickX;
		this.clickY = clickY;
		toByteArray();
	}

	public byte[] intToLByte(int i)
	{
		byte abyte0[] = new byte[4];
		abyte0[0] = (byte)(i & 0xff);
		abyte0[1] = (byte)(0xff & i >> 8);
		abyte0[2] = (byte)(0xff & i >> 12);
		abyte0[3] = (byte)(0xff & i >> 24);
		return abyte0;
	}
	
	public void toByteArray()
	{
		byteBuf = new byte[28];
		System.arraycopy(intToLByte(cmd), 0, byteBuf, 0, 4);
		System.arraycopy(intToLByte(x1), 0, byteBuf, 4, 4);
		System.arraycopy(intToLByte(y1), 0, byteBuf, 8, 4);
		System.arraycopy(intToLByte(x2), 0, byteBuf, 12, 4);
		System.arraycopy(intToLByte(y2), 0, byteBuf, 16, 4);
		System.arraycopy(intToLByte(clickX), 0, byteBuf, 20, 4);
		System.arraycopy(intToLByte(clickY), 0, byteBuf, 24, 4);

	}
}
